package com.ciccwm.core.exception;

import com.ciccwm.core.response.ResultCode;
import lombok.Getter;

/**
 * 业务异常.
 *
 * @author ciccwm
 */
@Getter
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码.
     */
    private final int code;

    /**
     * 错误消息.
     */
    private final String message;

    /**
     * 构造函数.
     *
     * @param message 错误消息
     */
    public BusinessException(String message) {
        this(ResultCode.BUSINESS_ERROR.getCode(), message);
    }

    /**
     * 构造函数.
     *
     * @param code 错误码
     * @param message 错误消息
     */
    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 构造函数.
     *
     * @param resultCode 响应码
     */
    public BusinessException(ResultCode resultCode) {
        this(resultCode.getCode(), resultCode.getMessage());
    }

    /**
     * 构造函数.
     *
     * @param resultCode 响应码
     * @param message 错误消息
     */
    public BusinessException(ResultCode resultCode, String message) {
        this(resultCode.getCode(), message);
    }

    /**
     * 获取错误码.
     *
     * @return 错误码
     */
    public int getCode() {
        return code;
    }
} 
